﻿using Max.PH5_2103A.Shopping.Frame.Domain;
using Max.PH5_2103A.Shopping.Frame.Domain.EFCore_DbFirst;
using Microsoft.EntityFrameworkCore;

namespace Max.PH5_2103A.Shopping.Frame.DAL
{
    /// <summary>
    /// EFCore的上下文
    /// </summary>
    public partial class MyDbContext : DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }


        public virtual DbSet<TbOrderDetail> TbOrderDetails { get; set; } = null!;
        public virtual DbSet<TbOrderInfo> TbOrderInfos { get; set; } = null!;
        public virtual DbSet<TbOrderLogistic> TbOrderLogistics { get; set; } = null!;
        public virtual DbSet<TbOrderLogisticDetail> TbOrderLogisticDetails { get; set; } = null!;
        public virtual DbSet<TbProductBrand> TbProductBrands { get; set; } = null!;
        public virtual DbSet<TbProductSku> TbProductSkus { get; set; } = null!;
        public virtual DbSet<TbProductSkuImage> TbProductSkuImages { get; set; } = null!;
        public virtual DbSet<TbProductSpuSpec> TbProductSpuSpecs { get; set; } = null!;
        public virtual DbSet<TbProudctCategory> TbProudctCategories { get; set; } = null!;
        public virtual DbSet<TbUser> TbUsers { get; set; } = null!;



        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TbOrderDetail>(entity =>
            {
                entity.ToTable("tb_order_detail");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.Price).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.Skuid).HasColumnName("SKUId");

                entity.Property(e => e.Skuimage).HasColumnName("SKUImage");

                entity.Property(e => e.Skuname).HasColumnName("SKUName");

                entity.Property(e => e.State).HasDefaultValueSql("(N'0')");
            });

            modelBuilder.Entity<TbOrderInfo>(entity =>
            {
                entity.ToTable("tb_order_info");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.Amount).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.CreatedTime).HasDefaultValueSql("(getdate())");

                entity.Property(e => e.IsDelete)
                    .IsRequired()
                    .HasDefaultValueSql("(N'false')");

                entity.Property(e => e.OrderState).HasDefaultValueSql("(N'0')");

                entity.Property(e => e.PayAmount).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.RateAmount)
                    .HasColumnType("decimal(18, 2)")
                    .HasDefaultValueSql("(N'0')");
            });

            modelBuilder.Entity<TbOrderLogistic>(entity =>
            {
                entity.ToTable("tb_order_logistic");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.CreatedTime).HasDefaultValueSql("(getdate())");
            });

            modelBuilder.Entity<TbOrderLogisticDetail>(entity =>
            {
                entity.ToTable("tb_order_logistic_detail");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.CreatedTime).HasDefaultValueSql("(getdate())");
            });

            modelBuilder.Entity<TbProductBrand>(entity =>
            {
                entity.ToTable("tb_product_brand");
            });

            modelBuilder.Entity<TbProductSku>(entity =>
            {
                entity.ToTable("tb_product_sku");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.CreatedTime).HasDefaultValueSql("(getdate())");

                entity.Property(e => e.EnableStock).HasDefaultValueSql("(N'0')");

                entity.Property(e => e.Flag).HasDefaultValueSql("(N'00000000')");

                entity.Property(e => e.InPrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasDefaultValueSql("(N'0')");

                entity.Property(e => e.IsDelete)
                    .IsRequired()
                    .HasDefaultValueSql("(CONVERT([bit],(0)))");

                entity.Property(e => e.LockStock).HasDefaultValueSql("(N'0')");

                entity.Property(e => e.MarketPrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasDefaultValueSql("(N'0')");

                entity.Property(e => e.ProcureDate).HasDefaultValueSql("('0001-01-01T00:00:00.0000000')");

                entity.Property(e => e.SaleNumber).HasDefaultValueSql("(N'0')");

                entity.Property(e => e.SalePrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasDefaultValueSql("(N'0')");

                entity.Property(e => e.State).HasDefaultValueSql("(N'0')");

                entity.Property(e => e.Stock).HasDefaultValueSql("(N'0')");
            });

            modelBuilder.Entity<TbProductSkuImage>(entity =>
            {
                entity.ToTable("tb_product_sku_image");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.Skuid).HasColumnName("SKUId");
            });

            modelBuilder.Entity<TbProudctCategory>(entity =>
            {
                entity.ToTable("tb_proudct_category");

                entity.Property(e => e.State).HasDefaultValueSql("(N'0')");
            });

            modelBuilder.Entity<TbUser>(entity =>
            {
                entity.ToTable("tb_user");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.State).HasDefaultValueSql("(N'0')");
            });

            modelBuilder.Entity<TbProductSpuSpec>(entity =>
            {
                entity.ToTable("tb_product_spu_spec");

                entity.Property(e => e.Id).HasDefaultValueSql("(newid())");

                entity.Property(e => e.SpecName)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasComment("规格名称");

                entity.Property(e => e.SpecValue)
                    .HasMaxLength(10)
                    .IsFixedLength()
                    .HasComment("规格值");
            });

            OnModelCreatingPartial(modelBuilder);
        }


        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);

    }
}